home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / EFileDlg.tcl.z / EFileDlg.tcl
Encoding:
Text File  |  1999-01-26  |  2.8 KB  |  100 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # This file demonstrates the use of the tixExFileSelectDialog widget --
  10. # This is a neat file selection dialog that will make your apps look
  11. # real good!
  12. #
  13. proc RunSample {w} {
  14.  
  15.     # Create an entry for the user to input a filename. If he can't
  16.     # bother to type in the name, he can press the "Browse ..." button
  17.     # and call up the file dialog
  18.     #
  19.     frame $w.top -border 1 -relief raised
  20.  
  21.     tixLabelEntry $w.top.ent -label "Select A File:" -labelside top \
  22.     -options {
  23.         entry.width 25
  24.         entry.textVariable demo_efdlg_filename
  25.         label.anchor w
  26.     }
  27.     bind [$w.top.ent subwidget entry] <Return> "efdlg:okcmd $w"
  28.  
  29.     uplevel #0 set demo_efdlg_filename {}
  30.  
  31.  
  32.     button $w.top.btn -text "Browse ..." -command "efdlg:browse"
  33.  
  34.     pack $w.top.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4
  35.     pack $w.top.btn -side left -anchor s -padx 4 -pady 4
  36.  
  37.     # Use a ButtonBox to hold the buttons.
  38.     #
  39.     tixButtonBox $w.box -orientation horizontal
  40.     $w.box add ok     -text Ok     -underline 0 -command "efdlg:okcmd $w" \
  41.     -width 6
  42.     $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  43.     -width 6
  44.  
  45.     pack $w.box -side bottom -fill x
  46.     pack $w.top -side top -fill both -expand yes
  47. }
  48.  
  49. # Pop up a file selection dialog
  50. #
  51. proc efdlg:browse {} {
  52.     # [Hint]
  53.     # The best way to use an ExFileSelectDialog is not to create one yourself
  54.     # but to call the command "tix filedialog". This command creates one file
  55.     # dialog box that is shared by different parts of the application.
  56.     # This way, your application can save resources because it doesn't
  57.     # need to create a lot of file dialog boxes even if it needs to input
  58.     # file names at a lot of different occasions.
  59.     #
  60.     set dialog [tix filedialog tixExFileSelectDialog]
  61.     $dialog config -command efdlg:select_file
  62.  
  63.     $dialog subwidget fsbox config -filetypes {
  64.     {{*}        {*     -- All files}}
  65.     {{*.txt}    {*.txt -- Text files}}
  66.     {{*.c}        {*.c   -- C source files}}
  67.     }
  68.  
  69.     $dialog popup
  70. }
  71.  
  72. proc efdlg:select_file {file} {
  73.     global demo_efdlg_filename 
  74.  
  75.     set demo_efdlg_filename $file
  76. }
  77.  
  78. proc efdlg:okcmd {w} {
  79.     global demo_efdlg_filename 
  80.  
  81.     if {$demo_efdlg_filename != {}} {
  82.     puts "You have selected the file $demo_efdlg_filename"
  83.     } else {
  84.     puts "You haven't selected any file"
  85.     }
  86.  
  87.     destroy $w
  88. }
  89.  
  90. # This "if" statement makes it possible to run this script file inside or
  91. # outside of the main demo program "widget".
  92. #
  93. if {![info exists tix_demo_running]} {
  94.     wm withdraw .
  95.     set w .demo
  96.     toplevel $w
  97.     RunSample $w
  98.     bind .demo <Destroy> exit
  99. }
  100.